package com.vandzi.android.androidcode.service;

import java.util.List;

import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;

public class InstalledApplicationsService {

	/**
	 * Return true if application with name @applicationName is installed on
	 * device
	 * 
	 * @param applicationName
	 * @param packageManager
	 * @return
	 */
	public static boolean isApplicationInstalled(String packageName,
			PackageManager packageManager) {
		if (packageName != null) {
			List<ApplicationInfo> packs = packageManager
					.getInstalledApplications(0);
			for (int i = 0; i < packs.size(); i++) {
				ApplicationInfo ai = packs.get(i);
				String appPackage = ai.packageName;

				if (appPackage.equals(packageName)) {
					return true;
				}
			}
		}
		return false;
	}

}
